package main

import (
	"fmt"
)

func frequencySort(s string) string {
	count := make(map[rune]int) //声明，初始化一个map
	//生成一个hashmap
	for _, char := range s {
		count[char]++
	}

	//输出最多到最少的内容

	//最终输出字符串
	var des []rune

	tempnum := 0
	var tempkey rune

	for i := 0; i < len(s); i++ {
		for char, num := range count {
			if num > tempnum {
				tempkey = char
				tempnum = num

			}
		}

		delete(count, tempkey)

		for j := 0; j < tempnum; j++ {
			des = append(des, tempkey)

		}
		tempnum = 0

	}

	return string(des)
}

func main() {
	s := "tree"
	des := frequencySort(s)
	fmt.Println(des)

}
